package com.example.universitylibraryback.controller;

import com.example.universitylibraryback.entity.BorrowRequest;
import com.example.universitylibraryback.service.RuleEngineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/borrow")
public class BookBorrowController {
    
    @Autowired
    private RuleEngineService ruleEngineService;
    
    @PostMapping("/validate")
    public BorrowRequest validateBorrowRequest(@RequestBody BorrowRequest borrowRequest) {
        // 应用规则引擎验证借阅请求
        BorrowRequest result = ruleEngineService.executeBorrowRules(borrowRequest);
        
        // 记录规则执行日志
        System.out.println("借阅请求验证结果：" +
            (result.getApproved() ? "批准，借阅天数：" + result.getActualBorrowDays() : 
                                  "拒绝，原因：" + result.getRejectionReason()));
        
        return result;
    }
}